package com.gmail.shazi199.satoriex.move;

public class BasicBossMovement extends Movement {
    private double currentX;
    private double currentY;
    private double targetX;
    private double targetY;

    private int waitFrame = 0;

    public BasicBossMovement(double currentX, double currentY, double targetX, double targetY) {
        super();
        this.currentX = currentX;
        this.currentY = currentY;
        this.targetX = targetX;
        this.targetY = targetY;
    }

    @Override
    public double[] getNextPosition() {
        update();
        return new double[] { this.currentX, this.currentY };
    }

    private void update() {
        if (this.waitFrame == 60) {
            this.setEnded(true);
            this.waitFrame = 0;
            return;
        }
        if (this.waitFrame > 0) {
            this.waitFrame++;
            return;
        }
        if (this.isEnded()) {
            return;
        }
        double offsetX = (this.targetX - this.currentX) / 15;
        double offsetY = (this.targetY - this.currentY) / 15;
        if (Math.abs(offsetX) < 0.01) {
            this.currentX = this.targetX;
            offsetX = 0;
        }
        if (Math.abs(offsetY) < 0.01) {
            this.currentY = this.targetY;
            offsetY = 0;
        }
        if (offsetX == 0 && offsetY == 0) {
            this.waitFrame = 1;
        } else {
            this.currentX += offsetX;
            this.currentY += offsetY;
        }
    }
}
